package com.persia.dao

import com.persia.model.Temperature
import org.squeryl.PrimitiveTypeMode._
import com.persia.persistence.Db

trait DataStoreImpl extends DataStore{
   def add(temperature: Double,user:String):Unit ={
     val tem = new Temperature()
     tem.user = user
     tem.temperature = temperature
     tem.datetime = java.lang.System.currentTimeMillis
     
     transaction{
       Db.temperature.insert(tem)
     }
     
   }
   
   def getByDate(startTime: Long,endTime: Long): List[Temperature] ={
     transaction{
        val records = from(Db.temperature)(t => 
          where(
            (t.datetime gte startTime)
            and 
            (t.datetime lte endTime)
                
            ) 
          select(t))
            records.toList
     }
   }
}